package com.datamation.swadeshi.view;

import android.annotation.SuppressLint;
import android.app.ActionBar;
import android.app.ActionBar.Tab;
import android.app.ActionBar.TabListener;
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.SearchView;
import android.widget.Toast;
import android.widget.SearchView.OnQueryTextListener;

import com.datamation.swadeshi.R;
import com.datamation.swadeshi.adapter.SetTitleAdapter;



@SuppressLint("NewApi") 
public class FragmentInventoryControlDamageTrans extends Fragment  {
	View view;
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		view = inflater.inflate(R.layout.inventory_control_damagemain, container, false);
		
		//lvInvoiceList = (ListView) view.findViewById(R.id.lvPhoneInvoiceList);
		
		//getActivity().getActionBar().removeAllTabs();
		//getActivity().getActionBar().setNavigationMode(0);
		setHasOptionsMenu(true);
//       
		SetTitleAdapter adapter =new SetTitleAdapter();
		adapter.createCutomActionBarTitle("Damage Transfer", getActivity());
		

	
//		lvInvoiceList.setOnItemClickListener(new OnItemClickListener() {
//
//			@Override
//			public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//
//				
//			}
//		});
//		lvInvoiceList.setOnItemLongClickListener(new OnItemLongClickListener() {
//
//			@Override
//			public boolean onItemLongClick(AdapterView<?> parent, View view,
//					int position, long id) {
//				
//				// TODO Auto-generated method stub
//				OrdHed ordHed = arrayList.get(position);
//				delete(getActivity(), ordHed.getFORDHED_REFNO());
//				
//				return false;
//			}
//		});
		
		//back button disable 
        view.setFocusableInTouchMode(true);
        view.requestFocus();
        view.setOnKeyListener(new View.OnKeyListener() {
		        @Override
		        public boolean onKey(View v, int keyCode, KeyEvent event) {
		            Log.i("", "keyCode: " + keyCode);
		            if( keyCode == KeyEvent.KEYCODE_BACK ) {
		            	Toast.makeText(getActivity(),"Back Navigationid is disable", Toast.LENGTH_SHORT).show();
		               // getFragmentManager().popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
		                return true;
		            }else if ((keyCode == KeyEvent.KEYCODE_HOME)) {
		    			
		    			getActivity().finish();
		    			
		    			return true;

		    		} else {
		                return false;
		            }
		        }
		    });
        
        
		return view;
	}
	@Override
	public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
		
		for(int i = 0; i < menu.size(); ++i){
			menu.removeItem(menu.getItem(i).getItemId());
		}
		
		inflater.inflate(R.menu.frag_stockloading_phone_menu, menu);
		SearchView searchView = (SearchView) menu.findItem(R.id.action_customer_search_phone).getActionView();
		searchView.setOnQueryTextListener(new OnQueryTextListener() {
			
			@Override
			public boolean onQueryTextSubmit(String query) {
				return false;
			}
			
			@Override
			public boolean onQueryTextChange(String newText) {
				


				return false;
			}
		});
		
	
		super.onCreateOptionsMenu(menu, inflater);
	}
	
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		if(item.getItemId() == R.id.action_stockloading_phone_new)
		{
			FragmentTransaction transaction = getFragmentManager().beginTransaction();
			transaction.replace(R.id.frame_container, new FragmentInventoryControlDamageMain());
			transaction.addToBackStack(null);
			transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
			transaction.commit();
		}
		return super.onOptionsItemSelected(item);
	}
	
}
